package light.head.model.inv;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import light.head.framework.entity.ExcelField;

import org.hibernate.annotations.Formula;

/**
 * 库存信息
 * @author yy
 *
 */
@Entity
@Table
public class InvStorage implements Serializable {

	private static final long serialVersionUID = -133208090818663418L;
	
	private Integer code;
	private Integer cc;					// 商品编号（注：商品入库的时候要判断商品编号cc和sns 都一样才会加数量，否则新建一条库存信息 ）
	@ExcelField(order = 2, name = "序列号状态")
	private String setsnc;
	private Byte snc;					// 序列号状态 (1.没有序列号 2.一类序列号 3.唯一序列号)注意：这里是从入库单那里得来的
	private Integer oc;					// 机构编号
	private Integer dc;					// 仓库编号
	@ExcelField(order = 3, name = "数量")
	private Integer count;				// 数量
	private Boolean deleted= false;		// 是否删除
	@ExcelField(order = 5, name = "仓库名称")
	private String dname;				// 仓库名称
	@ExcelField(order = 1, name = "商品名称")
	private String cname;				// 商品名称
	@ExcelField(order = 4, name = "机构名称")
	private String on;					// 机构名称
	private Double price;				// 商品价格
	private String un;					// 单位
	private List<InvStorageDetail> detailList;
	private String fast;
	private String remark;
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column
	public Integer getCode() {
		return code;
	}
	@Column
	public Integer getCc() {
		return cc;
	}
	@Column
	public Integer getOc() {
		return oc;
	}
	@Column
	public Integer getDc() {
		return dc;
	}
	@Column
	public Integer getCount() {
		return count;
	}
	@Column
	public Byte getSnc() {
		return snc;
	}
	@Column
	public Boolean getDeleted() {
		return deleted;
	}
	@Column
	public String getRemark() {
		return remark;
	}
	@Formula("(SELECT c.name FROM InvCommodityInfo c WHERE c.code IN (SELECT ci.cc FROM InvCommodityItem ci WHERE ci.code = cc))")
	public String getCname() {
		return cname;
	}
	@Formula("(SELECT o.name FROM Organ o WHERE o.code = oc)")
	public String getOn() {
		return on;
	}
	@Formula("(SELECT ici.rp FROM InvCommodityItem ici WHERE ici.code = cc)")
	public Double getPrice() {
		return price;
	}
	
	@Formula("(SELECT d.name FROM InvDepot d WHERE d.code = dc)")
	public String getDname() {
		return dname;
	}
	@Formula("(SELECT ici.fast FROM InvCommodityItem ici WHERE ici.code = cc)")
	public String getFast() {
		return fast;
	}
	@Transient
	public List<InvStorageDetail> getDetailList() {
		return detailList;
	}
	@Transient
	public String getSetsnc() {
		return setsnc;
	}
	@Formula("(SELECT c.name FROM InvUnit c WHERE c.code IN (SELECT ci.uc FROM InvCommodityItem ci WHERE ci.code = cc))")
	public String getUn() {
		return un;
	}
	
	
	
	
	public void setUn(String un) {
		this.un = un;
	}
	public void setSetsnc(String setsnc) {
		this.setsnc = setsnc;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public void setFast(String fast) {
		this.fast = fast;
	}
	public void setPrice(Double double1) {
		this.price = double1;
	}
	public void setDname(String dname) {
		this.dname = dname;
	}
	public void setCname(String cname) {
		this.cname = cname;
	}
	public void setOn(String on) {
		this.on = on;
	}
	public void setDetailList(List<InvStorageDetail> detailList) {
		this.detailList = detailList;
	}
	public void setSnc(Byte snc) {
		if (null != snc && snc == 1){
			this.setSetsnc("没有序列号");
		}else if(null != snc && snc == 2) {
			this.setSetsnc("一类序列号 ");
		}else if(null != snc && snc == 3){
			this.setSetsnc("唯一序列号");
		}
		this.snc = snc;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public void setCc(Integer cc) {
		this.cc = cc;
	}
	public void setOc(Integer oc) {
		this.oc = oc;
	}
	public void setDc(Integer dc) {
		this.dc = dc;
	}
	public void setCount(Integer count) {
		this.count = count;
	}
	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}
	
	
}
